package test1230am;

public class Test19 {
    public static void main(String[] args) {
        // (19)元素3和元素2互换位置
        int[] arr = {5, 3, 7, 2, 6};
        m(arr ,3,2);
        for (int i = 0; i < arr.length; i++) {
            System.out.println(arr[i]);
        }
    }
    public static void m(int[] arr, int value1, int value2) {
        int index1 = -1, index2 = -1;

        // 查找第一个出现的value1的下标
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] == value1) {
                index1 = i;
                break;
            }
        }

        // 查找第一个出现的value2的下标
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] == value2) {
                index2 = i;
                break;
            }
        }


        if (index1 != -1 && index2 != -1) {
            int temp = arr[index1];
            arr[index1] = arr[index2];
            arr[index2] = temp;
        }
    }
}